package com.bw.a2207a.view.adapter

import android.widget.CheckBox
import android.widget.ImageView
import com.bw.a2207a.R
import com.bw.a2207a.bean.CartBean
import com.bw.a2207a.util.GlideUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import org.greenrobot.eventbus.EventBus

/**
 *
 * @ClassName: GoodsAdapter
 * @Description: java类作用描述
 * @Author: zhangyanchao
 * @CreateDate: 2024/10/23 4:00 PM
 * @Version: 1.0
 */
class CartAdapter(layoutResId: Int, data: MutableList<CartBean>) :
    BaseQuickAdapter<CartBean, BaseViewHolder>(layoutResId, data) {
    override fun convert(holder: BaseViewHolder, item: CartBean) {

        GlideUtil.loadImg(context, item.goods_default_icon, holder.getView<ImageView>(R.id.iv))
        holder.setText(R.id.tv_desc, item.goods_desc)
        holder.setText(R.id.tv_price, "${item.goods_default_price}元")
        holder.setText(R.id.tv_count, "X ${item.count}")
        //根据data 值设置CheckBox的选中状态
        holder.getView<CheckBox>(R.id.item_check).isChecked = item.isChecked
        val c = holder.getView<CheckBox>(R.id.item_check)
        holder.getView<CheckBox>(R.id.item_check).setOnClickListener {
            item.isChecked = c.isChecked
            EventBus.getDefault().post("cart")
        }
    }
}